home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / util / moni / Scout-src.lha / source / objects / scout_asm.asm < prev    next >
Encoding:
Assembly Source File  |  2002-02-13  |  12.0 KB  |  577 lines

  1. **
  2. * Scout - The Amiga System Monitor
  3. *
  4. *------------------------------------------------------------------
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. *
  20. * You must not use this source code to gain profit of any kind!
  21. *
  22. *------------------------------------------------------------------
  23. *
  24. * @author Andreas Gelhausen
  25. * @author Richard Körber <rkoerber@gmx.de>
  26. *
  27.  
  28.  
  29.  
  30.         include "objects/scout_asm.i"
  31.         include "exec/funcdef.i"
  32.         include "exec/exec_lib.i"
  33.  
  34.  
  35.         SECTION CODE
  36.  
  37.         xdef _MyCause
  38. _MyCause:
  39.         ;=================================
  40.         ; causes software interrupt
  41.         ;=================================
  42.         ;  > A0: Passed to SoftInt
  43.         ;  > A1: Int-Structure
  44.         ;  < D0: Return Code
  45.         movem.l a0-a6/d1-d7,-(sp)
  46.         move.l  $4.w,a6
  47.         move.l  IS_DATA(a1),a1
  48.         move.l  IS_CODE(a1),a2
  49.         jsr     (a2)
  50.         movem.l (sp)+,a0-a6/d1-d7
  51.         rts
  52.  
  53.  
  54.         xdef _NameCopy
  55. _NameCopy:
  56.         ;=================================
  57.         ;copy name (e.g. "euro72.monitor") to buffer, until '.' or null termination
  58.         ;  (also uppercase)
  59.         ;=================================
  60.         ;  > A0: ^Target
  61.         ;  > A1: ^Source
  62.         movem.l a0/a1,-(sp)
  63. copy_loop:
  64.         move.b  (a1)+,d0
  65.         beq     copy_done
  66.         cmp.b   #'.',d0
  67.         beq     copy_done
  68.         cmp.b   #'a',d0                 ;Upper Case
  69.         bcs     copy_ok
  70.         cmp.b   #'z',d0
  71.         bhi     copy_ok
  72.         sub.b   #32,d0
  73. copy_ok:
  74.         move.b  d0,(a0)+
  75.         bra     copy_loop
  76. copy_done:
  77.         move.b  #':',(a0)+
  78.         clr.b   (a0)+
  79.         movem.l (sp)+,a0/a1
  80.         rts
  81.  
  82.  
  83.  
  84.         xdef _GetCACR
  85. _GetCACR:
  86.         ;=================================
  87.         ;return current value of CACR in d0
  88.         ;=================================
  89.  
  90.         movem.l a5/a6,-(SP)
  91.         moveq.l #0,d0
  92.         move.l  _AbsExecBase,a6
  93.         move.w  AttnFlags(a6),d1
  94.         btst    #AFB_68020,d1
  95.         beq.s   _GetCACR_Exit
  96.  
  97.         lea     CACR_to_d0(PC),a5
  98.         jsr     _LVOSupervisor(a6)
  99. _GetCACR_Exit:
  100.         movem.l (SP)+,a5/a6
  101.         rts
  102.  
  103. CACR_to_d0:
  104.         movec.l CACR,D0
  105.         rte
  106.  
  107.  
  108.         xdef _GetPCR
  109. _GetPCR:
  110.         ;=================================
  111.         ;return current value of PCR in d0
  112.         ;=================================
  113.  
  114.         movem.l a5/a6,-(SP)
  115.         moveq.l #0,d0
  116.         move.l  _AbsExecBase,a6
  117.         move.w  AttnFlags(a6),d1
  118.         btst    #AFB_68060,d1
  119.         beq.s   _GetPCR_Exit
  120.  
  121.         lea     PCR_to_d0(PC),a5
  122.         jsr     _LVOSupervisor(a6)
  123. _GetPCR_Exit:
  124.         movem.l (SP)+,a5/a6
  125.         rts
  126.  
  127. PCR_to_d0:
  128.         dc.w    $4E7A,$0808             ; movec.l PCR,D0
  129.         rte
  130.  
  131.  
  132.  
  133.         xdef _GetVBR
  134.  
  135. _GetVBR:
  136.         ;=================================
  137.         ;return current value of VBR in d0
  138.         ;=================================
  139.  
  140.         movem.l a5/a6,-(SP)
  141.         moveq.l  #0,d0
  142.         move.l  _AbsExecBase,a6
  143.         move.w  AttnFlags(a6),d1
  144.         btst    #AFB_68010,d1
  145.         beq.s    _GetVBR_Exit
  146.  
  147.         lea        VBR_to_d0(PC),a5
  148.         jsr        _LVOSupervisor(a6)
  149.  
  150. _GetVBR_Exit:
  151.    movem.l      (SP)+,a5/a6
  152.         rts
  153.  
  154. VBR_to_d0:
  155.         movec.l VBR,D0
  156.         rte
  157.  
  158.  
  159.         xdef _SetVBR
  160.  
  161. _SetVBR:
  162.         ;=========================
  163.         ;move Value from a0 to VBR
  164.         ;=========================
  165.         movem.l a5/a6,-(SP)
  166.         move.l  _AbsExecBase,a6
  167.         move.w  AttnFlags(a6),d0
  168.         btst    #AFB_68010,d0
  169.         beq.s    _SetVBR_Exit
  170.  
  171.         move.l  a0,d0                   ; We pass the new VBR in a0, because
  172.                                                 ; it is a pointer (and pointers are
  173.                                                  ; put in address registers).
  174.         lea        d0_to_VBR(PC),a5
  175.         jsr        _LVOSupervisor(a6)
  176.  
  177. _SetVBR_Exit:
  178.         movem.l (SP)+,a5/a6
  179.         rts
  180.  
  181. d0_to_VBR:
  182.         movec.l D0,VBR
  183.         rte
  184.  
  185.    xdef _SetPatches
  186.    xref _AbsExecBase
  187.  
  188. _SetPatches:
  189.         ;=================================
  190.         ;set patch for task switching
  191.         ;=================================
  192.    movem.l  d0-d4/a0-a6,-(sp)
  193.    move.l   _AbsExecBase,a6
  194.    jsr      _LVOForbid(a6)
  195.  
  196.    move.l   _CodeAddress,a5
  197.  
  198.    move.w   #-54,d0
  199.    lea      (a5),a0
  200.    exg.l    d0,a0
  201.    move.l   a6,a1
  202.    jsr      _LVOSetFunction(a6)
  203. ;   lea      _OldSwitch(pc),a0
  204. ;   move.l   d0,(a0)
  205.  
  206.    move.w   #_LVOAddTask,d0
  207.    lea      _MyAdd-_MySwitch(a5),a0
  208.    exg.l    d0,a0
  209.    move.l   a6,a1
  210.    jsr      _LVOSetFunction(a6)
  211. ;   lea      _OldAdd(pc),a0
  212. ;   move.l   d0,(a0)
  213.  
  214.    jsr      _LVOPermit(a6)
  215.    movem.l  (sp)+,d0-d4/a0-a6
  216.    rts
  217.  
  218.  
  219. _TaskNumber    EQU 128
  220. _LVOAddTime    EQU -42  
  221. _LVOSubTime    EQU -48  
  222. _LVOCmpTime    EQU -54  
  223. _LVOReadEClock EQU -60  
  224. _LVOGetSysTime EQU -66  
  225.  
  226.  
  227. ;-----------------------------------------------------------------
  228. ; Die hier folgenden Routinen werden vor der Installierung der
  229. ;  Patches kopiert!  (bis einschließlich _CodeAddress)
  230. ;-----------------------------------------------------------------
  231.  
  232.         xdef _MySwitch
  233.  
  234. _MySwitch:
  235.         ;=================================
  236.         ;patch routine for task switching
  237.         ;=================================
  238.    movem.l  d0/a0,-(sp)
  239.    move.b   _SwitchState(pc),d0
  240.    beq      _OldSwitchFunc
  241.  
  242. swstart:
  243.    movem.l  d1-d3/a1-a4/a6,-(sp)
  244.    lea      _OldTimeVal(pc),a4
  245.    move.l   _MyTVSecs(pc),(a4)+
  246.    move.l   _MyTVMicro(pc),(a4)
  247.  
  248.    move.l   _AsmTimerBase(pc),a6
  249.    lea      _MyTimeVal(pc),a0
  250.    jsr      _LVOGetSysTime(a6)
  251.  
  252.    cmp.l    #42,-(a4)
  253.    beq.s    swexit
  254.  
  255.    lea      _MyTimeVal(pc),a0
  256.    lea      _OldTimeVal(pc),a1
  257.    jsr      _LVOSubTime(a6)
  258.  
  259.    move.l   _AbsExecBase,a6
  260.    move.l   ThisTask(a6),d0
  261.  
  262.    move.l   _TaskPtr1(pc),a4
  263.    move.l   #_TaskNumber-1,d3
  264. swloop:
  265.    move.l   (a4),d1
  266.    cmp.l    d0,d1
  267.    beq.s    swfound
  268.    lea      8(a4),a4
  269.    dbf      d3,swloop
  270.  
  271.    move.l   _TaskPtr1(pc),a4
  272.    move.l   #_TaskNumber-1,d3
  273. swloop2:
  274.    move.l   (a4),d1
  275.    beq.s    swfound     ;Task noch nicht in der Tabelle
  276.    lea      8(a4),a4
  277.    dbf      d3,swloop2
  278.    bra.s    swexit      ;Task konnte nicht mehr in die Tabelle
  279.                         ; aufgenommen werden
  280.  
  281. swfound:
  282.    move.l   d0,(a4)
  283.    move.l   _MyTVMicro(pc),d0
  284.    add.l    d0,4(a4)
  285.    lea      _TotalMicros1(pc),a0
  286.    add.l    d0,(a0)
  287.    bra.s    swexit
  288. swnext:
  289.    lea      8(a4),a4
  290.    dbf      d3,swloop
  291.  
  292. swexit:
  293.    lea      _TotalMicros1(pc),a0
  294.    move.l   (a0),d0
  295.    andi.l   #$ff000000,d0
  296.    tst.l    d0
  297.    beq.s    swnoshift
  298.    lsr.l    #8,d0
  299.    lsr.l    #4,d0
  300.    move.l   d0,(a0)
  301.  
  302.    move.l   _TaskPtr1(pc),a4
  303.    move.l   #_TaskNumber-1,d3
  304. swshift:
  305.    cmp.l    #-2,(a4)
  306.    beq.s    swshiftnext
  307.  
  308.    move.l   4(a4),d0
  309.    lsr.l    #8,d0
  310.    lsr.l    #4,d0
  311.    move.l   d0,4(a4)
  312. swshiftnext:
  313.    lea      8(a4),a4
  314.    dbf      d3,swshift
  315.  
  316. swnoshift:
  317.    move.l   _AsmTimerBase(pc),a6
  318.    lea      _MyTimeVal(pc),a0
  319.    jsr      _LVOGetSysTime(a6)
  320.    movem.l  (sp)+,d1-d3/a1-a4/a6
  321.  
  322. _OldSwitchFunc:
  323.    movem.l  (sp)+,d0/a0
  324.    move.l   _OldSwitch(pc),-(sp)
  325.    rts
  326.  
  327.  
  328. _MyTimeVal:
  329. _MyTVSecs:     dc.l  42
  330. _MyTVMicro:    dc.l  0
  331.  
  332. _OldTimeVal:
  333. _OldTVSecs:    dc.l  0
  334. _OldTVMicro:   dc.l  0
  335.  
  336.  
  337.    xdef _SwitchState
  338.  
  339. _SwitchState:  dc.b  0,0
  340.  
  341.  
  342.         xdef _MyAdd
  343.  
  344. _MyAdd:
  345.         ;=================================
  346.         ;patch routine for task adding
  347.         ;=================================
  348. addstart:
  349.    movem.l  d1/d4/d6/a0/a4/a6,-(sp)
  350.    move.l   a1,d4
  351.    bsr.s    _OldAddFunc
  352.  
  353.    move.b   _SwitchState(pc),d1
  354.    beq.s    addexit
  355.  
  356. ;   move.l   _AbsExecBase,a6
  357. ;   jsr      _LVOForbid(a6)   ;Darf nicht verwendet werden! (Absturz)
  358.  
  359.    move.l   _TaskPtr1(pc),a4
  360.    move.l   #_TaskNumber-1,d6
  361. addloop:
  362.    move.l   (a4),d1
  363.    bne.s    addnext
  364.  
  365. addfound:
  366.    move.l   #-2,(a4)    ;added task = -2 
  367.    move.l   d4,4(a4)    ;task address
  368.    bra.s    addexit
  369. addnext:
  370.    lea      8(a4),a4
  371.    dbf      d6,addloop
  372.  
  373. addexit:
  374. ;   jsr      _LVOPermit(a6)
  375.    movem.l  (sp)+,d1/d4/d6/a0/a4/a6
  376.    rts
  377.  
  378. _OldAddFunc:
  379.    move.l   _OldAdd(pc),-(sp)
  380.    rts
  381.  
  382.  
  383.         xdef _ClearTaskData
  384.  
  385. ;-------------------------------------------------------------------
  386. ; Die Routine 'ClearTaskData' muß vor der Installierung der Patches
  387. ; aufgerufen werden!
  388. ;-------------------------------------------------------------------
  389.  
  390. _ClearTaskData:
  391.    movem.l  d0-d3/a0-a4/a6,-(sp)
  392.    move.b   _TaskPtrState(pc),d0
  393.    bne.s    ctstart
  394.  
  395.    lea      _TaskPtr1(pc),a4
  396.    jsr      _AllocTaskBuffer
  397.  
  398. ctstart:
  399.    move.l   _AbsExecBase,a6
  400.    jsr      _LVOForbid(a6)
  401.  
  402.    lea      _TaskPtr1(pc),a4     ;Pointer austauschen!
  403.    move.l   (a4),d0
  404.    move.l   4(a4),(a4)
  405.    move.l   d0,4(a4)
  406.  
  407.    lea      _TotalMicros1(pc),a4 ;TotalMicros austauschen!
  408.    move.l   (a4),d0
  409.    move.l   4(a4),(a4)
  410.    move.l   d0,4(a4)
  411.  
  412.    jsr      _LVOPermit(a6)
  413.  
  414.    moveq    #0,d0
  415.    move.l   _TaskPtr1(pc),a0
  416.    move.l   #_TaskNumber*2-1,d1
  417. ctloop:
  418.    move.l   d0,(a0)+
  419.    dbf      d1,ctloop
  420.  
  421.    lea      _TotalMicros1(pc),a0
  422.    move.l   #0,(a0)
  423.  
  424. ctexit:
  425.    movem.l  (sp)+,d0-d3/a0-a4/a6
  426.    rts
  427.  
  428.  
  429.         xdef _GetTaskData
  430.  
  431. _GetTaskData:
  432.    movem.l  d1-d3/a0,-(sp)
  433.    move.l   d0,d2
  434.  
  435.    move.l   _TaskPtr2(pc),a0
  436.    move.l   #_TaskNumber-1,d3
  437.    moveq    #0,d0
  438. gtloop:
  439.    move.l   (a0),d1
  440.    cmp.l    d1,d2
  441.    bne.s    gtnext
  442.    move.l   4(a0),d0
  443. ;   move.l   d0,d1
  444. ;   lsl.l    #3,d1
  445. ;   lsl.l    #1,d0
  446. ;   add.l    d1,d0
  447.    bra.s    gtexit
  448. gtnext:
  449.    lea      8(a0),a0
  450.    dbf      d3,gtloop
  451. gtexit:
  452.    movem.l  (sp)+,d1-d3/a0
  453.    rts
  454.  
  455. _TaskPtr1:    dc.l  0     ;Die Reihenfolge dieser drei
  456. _TaskPtr2:    dc.l  0     ; Variablen unbedingt so lassen!
  457. _TaskPtrState: dc.b  0,0
  458.  
  459.  
  460.    xdef _TotalMicros1
  461.  
  462. _TotalMicros1: dc.l  0
  463. _TotalMicros2: dc.l  0
  464.  
  465.  
  466.    xdef _OldSwitch
  467.  
  468. _OldSwitch:    dc.l  0
  469.  
  470.  
  471.    xdef _OldAdd
  472.  
  473. _OldAdd:    dc.l  0
  474.  
  475.  
  476.         xdef _GetAddedTask
  477.  
  478. _GetAddedTask:
  479.    movem.l  d1/d6/a4,-(sp)
  480.    move.l   _TaskPtr2(pc),a4
  481.    move.l   #_TaskNumber-1,d6
  482.    moveq    #0,d0
  483.    move.l   #-2,d1
  484. galoop:
  485.    cmp.l    (a4),d1
  486.    bne.s    ganext
  487.  
  488. gafound:
  489.    move.l   4(a4),d0
  490.    move.l   #0,(a4)
  491.    move.l   #0,4(a4)
  492.    bra.s    gaexit
  493. ganext:
  494.    lea      8(a4),a4
  495.    dbf      d6,galoop
  496.  
  497. gaexit:
  498.    movem.l  (sp)+,d1/d6/a4
  499.    rts
  500.  
  501.  
  502.    xdef _AsmTimerBase
  503.  
  504. _AsmTimerBase:
  505.     dc.l  0
  506.  
  507.  
  508.    xdef _CodeAddress
  509.  
  510. _CodeAddress:
  511.     dc.l  0
  512.  
  513. ;-----------------------------------------------------------------
  514. ; Ab hier kommen Dinge, die nicht für die Patches kopiert werden!
  515. ;-----------------------------------------------------------------
  516.  
  517. _AllocTaskBuffer:          ;a4: Adresse von TaskPtr1
  518.    movem.l  d0-d4/a4/a6,-(sp)
  519.    move.l   _AbsExecBase,a6
  520.    move.l   #_TaskNumber*16+8,d0
  521.    move.l   #$10001,d1
  522.    jsr      _LVOAllocMem(a6)
  523.    move.l   d0,d4
  524.    beq.s    atbx
  525.  
  526.    jsr      _LVOForbid(a6)
  527.  
  528.    move.l   #_TaskNumber*16+8,d0
  529.    move.l   d4,a1
  530.    jsr      _LVOFreeMem(a6)
  531.  
  532.    move.l   #_TaskNumber*8+4,d0
  533.    move.l   #$50001,d1
  534.    jsr      _LVOAllocMem(a6)
  535.    move.l   d0,(a4)
  536.    beq.s    atbx
  537.  
  538.    move.l   #_TaskNumber*8+4,d0
  539.    move.l   #$50001,d1
  540.    jsr      _LVOAllocMem(a6)
  541.    move.l   d0,4(a4)
  542.    beq.s    ftb1
  543.    move.b   #1,8(a4)
  544. atbx:
  545.    jsr      _LVOPermit(a6)
  546.    movem.l  (sp)+,d0-d4/a4/a6
  547.    rts
  548.  
  549.  
  550. ;_FreeTaskBuffer:
  551. ;   movem.l  d0-d4/a4/a6,-(sp)
  552. ;   move.l   _AbsExecBase,a6
  553. ;;   jsr      _LVOForbid(a6)
  554. ;
  555. ;   lea      _TaskPtr1(pc),a4
  556. ;   move.l   _TaskPtr2(pc),d0
  557. ;   beq.s    ftb1
  558. ;   move.l   #_TaskNumber*8,a1
  559. ;   exg.l    d0,a1
  560. ;   jsr      _LVOFreeMem(a6)
  561. ;   clr.l    4(a4)
  562. ftb1:
  563.    move.l   _TaskPtr1(pc),d0
  564.    beq.s    ftbx
  565.    move.l   #_TaskNumber*8+4,a1
  566.    exg.l    d0,a1
  567.    jsr      _LVOFreeMem(a6)
  568.    clr.l    (a4)
  569.    move.b   #0,8(a4)
  570. ftbx:
  571.    jsr      _LVOPermit(a6)
  572.    movem.l  (sp)+,d0-d4/a4/a6
  573.    rts
  574.  
  575.  
  576.         END
  577.